package com.master.controller;

import com.master.config.HostHolder;
import com.master.domain.MiaoshaUser;
import com.master.domain.OrderInfo;
import com.master.service.GoodsService;
import com.master.service.OrderService;
import com.master.util.CodeMsg;
import com.master.util.Result;
import com.master.vo.GoodsVo;
import com.master.vo.OrderDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    @Autowired
    HostHolder hostHolder;

    @Autowired
    GoodsService goodsService;

    @RequestMapping("/detail")
    @ResponseBody
    public Result<OrderDetailVo> info(Model model,@RequestParam("orderId")long orderId){
        OrderInfo order = orderService.getOrderById(orderId);
        if(order == null){
            return Result.error(CodeMsg.ORDER_NOT_EXIIST);
        }
        //根据OrderInfo得到GoodsId
        long goodsId = order.getGoodsId();
        //根据商品id得到GoodsVo对象
        GoodsVo goodsVo = goodsService.getGoodsVoByGoodsId(goodsId);
        OrderDetailVo orderDetailVo = new OrderDetailVo();
        orderDetailVo.setOrder(order);
        orderDetailVo.setGoodsVo(goodsVo);
        return Result.success(orderDetailVo);
    }



}
